package com.example.myworkers.controller;/*
 *编写者：陆铭
 */

import com.example.myworkers.model.Menu;
import com.example.myworkers.service.IMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "menu")
@RestController

public class MenuController {

    @Autowired
    private IMenuService menuService;

    @ApiOperation(value = "查询所有菜单信息",notes = "获取菜单信息返回json字符串")
    @RequestMapping("/getMenu")
    public String getMenu(){
        return "Hello,Menu";
    }

    //增加
    @CrossOrigin
    @ApiOperation(value = "对菜单的增加方法")
    @GetMapping("/addMenu")
    public int addMenu(Menu menu){
        return menuService.insertMenu(menu);
    }

    //删
    @ApiOperation(value = "对菜单的删除方法")
    @GetMapping("/delMenu")
    public int Delete(int id){
        int returnValue=0;
        if(id!=0){
            Menu menu=new Menu();
            menu.setId(id);
            returnValue=menuService.deleteMenu(menu);
        }
        return returnValue;
    }

    //全部查
    @ApiOperation(value = "对菜单的全部查询方法")
    @GetMapping("/getAll")
    public List<Menu> getAllMenu(Menu menu){
        List<Menu> menuList=menuService.getAllMenu(menu);
        return menuList;
    }

    //单个查
    @ApiOperation(value = "对菜单的单个查询方法")
    @GetMapping("/getOne")
    public Menu getMenu(int id){
        Menu menu=new Menu();
        if(id!=0){
            Menu menu1=new Menu();
            menu1.setId(id);
            menu=menuService.getMenu(menu1);
            System.out.println("返回的数据集合为："+menu.getName());
        }
        return menu;
    }

    //改
    @ApiOperation(value = "对菜单的修改方法")
    @PostMapping("/editMenu")
    public int EditMenu(@RequestBody Menu menu){
        return menuService.updateMenu(menu);
    }
}
